package com.zyh.thread.demo3;

/**
 * @Author zyh
 * @Date 2024/8/8 11:32
 * @Description
 */

public class MyTask02 implements Runnable{
    private Object obj1;
    private Object obj2;

    public MyTask02(Object obj1, Object obj2) {
        this.obj1 = obj1;
        this.obj2 = obj2;
    }

    @Override
    public void run() {
        System.out.println("t2线程开始执行");
        synchronized (obj2){
            System.out.println("t2获取obj2");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (obj1){
                System.out.println("t2获取obj1");
            }
            System.out.println("t2释放obj1");
        }
        System.out.println("t2释放obj2");
    }
}
